package br.com.appestoque;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class CarregaConection {

	private static Connection connection = null;  
	
	public CarregaConection() {
		try {
			Class.forName(CarregaProperties.properties.getProperty("driver"));
			connection = DriverManager.getConnection(CarregaProperties.properties
							.getProperty("url"),CarregaProperties.properties
							.getProperty("user"),CarregaProperties.properties
							.getProperty("password"));
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public synchronized static Connection getInstance() {
//		Connection conn = null;
//        if (connection == null) {  
//        	new CarregaConection();
//        	conn = connection;
//        }else{
//        	conn = connection;
//        }
		new CarregaConection();
        return connection;
    }  
	
	public static void closeConnection() {
		try {
			connection.close();			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}